/*
 * All rights Reserved, Designed By DataDriver
 * Copyright:    DataDriver.Inc
 * Company:      Zhuo Wo Infomation Technology (ShangHai) CO.LTD
 */
package com.sun.servlet;

import javax.servlet.*;
import javax.servlet.annotation.HandlesTypes;
import javax.servlet.http.HttpServlet;
import java.util.EnumSet;
import java.util.Set;

/**
 * 在容器启动的时候@HandlesTypes()会将里面声明的类及其子类等全部传递过来
 */
@HandlesTypes({HttpServlet.class,Filter.class})
public class MyServletComtainerInitaal implements ServletContainerInitializer {

    @Override
    public void onStartup(Set<Class<?>> set, ServletContext servletContext) throws ServletException {
        //注册三大组件
        ServletRegistration.Dynamic servlet = servletContext.addServlet("userServlet", new UserServlet());
        //添加映射
        servlet.addMapping("/user");
        //注册监听器
        servletContext.addListener(UserListener.class);
        //注册过滤器
        FilterRegistration.Dynamic filter = servletContext.addFilter("userFilter", UserFilter.class);
        //配置过滤哪些信息[拦截所有请求]
        filter.addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST),true,"/*");
    }
}
